import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        long l,r;
        while(t -- > 0){
            l = sc.nextLong();
            r = sc.nextLong();
            if(l == r){
                System.out.println(0);
                continue;
            }
            int i = 0;
            for(i = 63;i >= 0;i --){
                if((l >> i) != (r >> i)){
                    long res = ((long)1 << (i + 1)) - (long)1;
                    System.out.println(res);
                    break;
                }
            }

        }

    }
}